#!/bin/bash

root_path=$PWD
install_path=$root_path'/_install'

# create tar _install
if [ ! -d $install_path ]
then
    echo -e "\e[0;32;1m[info] : create _install success\e[0m"
    mkdir $PWD'/tar'
fi

#export PREFIX=/home/sammy/project/selinux/_install
#export DESTDIR=/home/sammy/project/selinux/_install
export PREFIX=$install_path
export DESTDIR=$install_path
export CFLAGS=-I$DESTDIR/include
export LDFLAGS=-L$DESTDIR/lib

echo "PREFIX  : "$PREFIX
echo "DESTDIR : "$DESTDIR
echo "CFLAGS  : "$CFLAGS
echo "LDFLAGS : "$LDFLAGS

root_path=$PWD
SUBDIRS=(libsepol libselinux libsemanage checkpolicy secilc policycoreutils dbus gui mcstrans python restorecond sandbox semodule-utils)
PYSUBDIRS=(libselinux libsemanage)

echo "SUBDIRS : "${SUBDIRS[1]} ${SUBDIRS[10]}

for subdir in ${SUBDIRS[@]}
do
	echo ""
	echo $subdir
	echo ""
	cd $subdir && ./build.sh
	cd $root_path
done

for subdir in ${PYSUBDIRS[@]}
do
	echo $subdir
	cd $subdir && ./build.sh
	cd $root_path
done
